package com.situ.config;

import com.situ.interceptor.LoginInterceptor;
import com.situ.interceptor.ShoppingLoginINterceptor;
import com.situ.util.SYS;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class EasyWebMVCConfig implements WebMvcConfigurer {

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 将上传的图片路径映射为可访问的URL
        registry.addResourceHandler(SYS.FILE_UPLOAD_URL + "/**")
                .addResourceLocations("file:" + SYS.FILE_UPLOAD_DIR);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截请求
       registry.addInterceptor(new ShoppingLoginINterceptor()).addPathPatterns("/cart.html");
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/login.html");
    }





}
